package tools.yangkl.utils;

/**
 * @author yangkl
 * @since 2022/11/30
 **/
public class CommonUtils {
    private CommonUtils() {

    }

    public static int compare(Integer x, Integer y) {
        if (x == null) {
            if (y == null) {
                return 0;
            } else {
                return -1;
            }
        }
        if (y == null) {
            return 1;
        }

        if (x.equals(y)) {
            return 0;
        } else {
            return x < y ? -1 : 1;
        }
    }

    @SuppressWarnings("unchecked")
    public static int compare(Comparable x, Comparable y) {
        if (x == null) {
            if (y == null) {
                return 0;
            } else {
                return -1;
            }
        }
        if (y == null) {
            return 1;
        }

        return x.compareTo(y);
    }
}
